import java.util.ArrayList;
import java.util.List;

public class DistributeGenerator {

    //限制：大概lambda*MaxFramePerStation个时间槽后就不会在继续生成帧
    //因此上述数值应该与总时间槽数差不多相等
    static final double lamda = 400;
    static final int MaxFramePerStation = 2000;

    // 获得满足泊松分布的随机数,即Frame到达间隔
    private static int getPossionVariable(double lamda) {
        int x = 0;
        double y = Math.random(), cdf = getPossionProbability(x, lamda);
        while (cdf < y) {
            x++;
            cdf += getPossionProbability(x, lamda);
        }
        return x;
    }

    private static double getPossionProbability(int k, double lamda) {
        double c = Math.exp(-lamda), sum = 1;
        for (int i = 1; i <= k; i++) {
            sum *= lamda / i;
        }
        return sum * c;
    }

    public static int[] getPossionList() {
        int[] array = new int[MaxFramePerStation];
        array[0] = getPossionVariable(lamda);
        for (int i = 1; i < MaxFramePerStation; i++) {
            array[i] = array[i - 1] + getPossionVariable(lamda);
        }
        for (int i = 1; i < MaxFramePerStation; i++) {
            System.out.print("array[" + i + "]:" + array[i] + ";");
        }
        System.out.println();
        return array;
    }
}